const path = require('path');
const Koa = require('koa');
const cors = require('@koa/cors');
const proxy = require('koa-server-http-proxy');
const static = require('koa-static');
const logger = require('koa-logger');

const app = new Koa();

app
  .use(cors())
  .use(proxy('/api', {
    target: process.env.BACKEND_TARGET || 'api.yangpihu.net',
    pathRewrite: { '^/api': '' },
    changeOrigin: true
  }))
  .use(static(path.join(__dirname)+'/public/'))
  .use(logger());

app.listen(process.env.PORT || 10236);
